// pages/particulars-new/particulars-new.js
var app = getApp();
var com = require('../../common.js');
Page({
  data: {
    id: '',
    info: {},
    pricein: 0,
    reid: ''
  },
  onLoad: function(options) {
    console.log(options)
    this.setData({
      id: options.id
    })
    this.onCounponInfo()
  },
  onReady: function() {},
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {},
  onShareAppMessage: function() {},
  priceInput(e) {
    var _this = this
    _this.setData({
      pricein: e.detail.value
    })
  },
  onCounponInfo() {
    var Б = this,
      id = Б.data.id,
      url = app.link.roundGood + id + '.st'
    com.link(url, {}, function(rep) {
      console.log(rep);
      Б.setData({
        info: rep.data.response,
        reid: rep.data.response.refund.id,
        pricein: rep.data.response.order.order_amount
      })
    }, 'GET')

  },
  codeList: function(e) {
    let index = e.currentTarget.dataset.index;
    let _this = this
    if (index == 0) {
      wx.showModal({
        title: '温馨提示',
        content: '确认拒绝退款吗？',
        success(res) {
          if (res.confirm) {
            com.link(app.link.handle + _this.data.reid + '.st', {
              agree: 0
            }, function(res) {
              console.log(res);
              if (res.data.state) {
                wx.showToast({
                  title: res.data.message,
                  icon: 'none'
                })
                setTimeout(() => {
                  wx.navigateBack({
                    delta: 1
                  })
                }, 1500)
              } else {
                wx.showToast({
                  title: res.data.message,
                  icon: 'none'
                })
              }
            })
          }
        }
      })
    }
    if (index == 1) {
      wx.showModal({
        title: '温馨提示',
        content: '确认退款吗？',
        success(res) {
          if (res.confirm) {
            com.link(app.link.handle + _this.data.reid + '.st', {
              agree: 1,
              amount: _this.data.pricein
            }, function(res) {
              console.log(res);
              if (res.data.state) {
                wx.showToast({
                  title: res.data.message,
                  icon: 'none'
                })
                setTimeout(() => {
                  wx.navigateBack({
                    delta: 1
                  })
                }, 1500)
              } else {
                wx.showToast({
                  title: res.data.message,
                  icon: 'none'
                })
              }
            })
          }
        }
      })
    }
    if (index == 2) {
      wx.navigateTo({
        url: '../logistics/logistics?id=' + e.currentTarget.id,
      })
    }
  },
})